package com.lanhao.aot.exchager;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;

@RestController
@RequestMapping("/exchanger")
public class ExchangerConstroller {
	
	@GetMapping("/getValue")
	public ResponseEntity<?> getValue() {
		String exchange = StringUtils.EMPTY;
		try {
			ExchangerUtil.tpool.execute(() -> {
				ExchangerUtil.doAsyncTask();
			});
			exchange = Thread.currentThread().getName() + ":" + ExchangerUtil.exchanger.exchange(null, 3L, TimeUnit.SECONDS);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (TimeoutException e) {
			e.printStackTrace();
		}
		return new ResponseEntity<>(exchange, HttpStatus.OK);
	}
}
